package jianzhiOffer;

import java.util.HashMap;
import java.util.Map;

//剑指 Offer 48. 最长不含重复字符的子字符串
public class Num48_lengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        Map<Character , Integer> map = new HashMap<>();
        int res = 0;
        int temp = 0;//保存无重复字串长度
        for (int j = 0; j < s.length(); j++) {
            //获取重复索引
            int i = map.getOrDefault(s.charAt(j) , -1);
            //更新重复值
            map.put(s.charAt(j) , j);
            temp = temp >= j - i ? j - i : temp + 1;
            res = Math.max(temp,res);

        }

        return res;



    }
}
